//*********************************************************
//*日历
//*********************************************************
//建立日期对象
	var sysdate = new Date();
	var currentYear = sysdate.getYear();
	var currentMonth = sysdate.getMonth();
	var currentDay = sysdate.getDate();
	var currentWeek = sysdate.getDay();
//初始化日期下拉列表位当前日期
function initCalendar(path){

	var calendar = document.getElementById("calendar");
	//获得日期下拉列表控件
	var year = document.getElementById("year");
	var month = document.getElementById("month");
	//设置年份下拉列表
	innitYear(currentYear);
	
	//设置月份下拉列表
	innitMonth(currentMonth);
	
	
	//设置表格内容
	setCalendar(path);
}

//判断是否是闰年
function isLeapYear(year){
	if(year%4==0&&((year%100!=0)||year%400==0)){
		return true;
	}
	return false;
}

//清空下拉列表
function cleanSelect(selectId){
	var selectObj = document.getElementById(selectId);
	var optionLength = selectObj.length;
	for(var i = 0;i < optionLength;i++){

		selectObj.remove(0);
	}
}

//获得某年某月的天数
function getDayCount(year,month){
	if(month == 4 || month == 6 || month == 9 || month == 11){
		return 30;	
	}else if(month == 2){
		if(isLeapYear(year)){
			return 29;	
		}else{
			return 28;	
		}
	}else{
		return 31;	
	}
}

//绘制日历
function setCalendar(path){
	//获得用户选择的日期
	var year = document.getElementById("year").value;
	var month = document.getElementById("month").value;
	//建立日期对象
	var chooseDate = new Date(year,month-1,1);
	//获得该日期所在月第一天是星期几
	var startWeek = chooseDate.getDay();
	//处理星期，如果是装换成0
	startWeek = startWeek % 7;
	//获得该月有多少天
	var daycount = getDayCount(year,month);
	//获得日历表格对象
	var calendar = document.getElementById("calendar");
	//清空日历表格
	cleanCalendar();
	//绘制表格内容
	for(var i = 1;i <= daycount;i++){
		var tempDate = year+"-"+month+"-"+i;
		if(i == day){
			calendar.cells[7 + startWeek + i].innerHTML = "<strong><a href='"+path+"/pendWork/pendWork!workListByType.action?dateStatus=3&date="+tempDate+"'>"+i+"</a></strong>";
			
			calendar.cells[7 + startWeek + i].bgColor = "#DDEDF9";
		}else{
			calendar.cells[7 + startWeek + i].innerHTML = "<a href='"+path+"/pendWork/pendWork!workListByType.action?dateStatus=3&date="+tempDate+"'>"+i+"</a>";
		}
	}
}

//将日历清空
function cleanCalendar(){
	var calendar = document.getElementById("calendar");
	for(var i = 0;i < 50;i++){
		alert(i + "," + calendar.cells[i]);
		//calendar.cells[i].innerHTML = "&nbsp;";
		//calendar.cells[i].bgColor = "#FFFFFF";
	}	
}


//获得今天日期
function getToday(){
	cleanSelect("year");
	cleanSelect("month");
	initCalendar();
}


function innitYear(strYear) //年份的下拉框
{
    if (strYear.match(/\D/)!=null){alert("年份输入参数不是数字！");return;}
    var m = (strYear) ? strYear : new Date().getFullYear();
    if (m < 1000 || m > 9999) {alert("年份值不在 1000 到 9999 之间！");return;}
    var n = m - 50;
    if (n < 1000) n = 1000;
    if (n + 101 > 9999) n = 9974;
    var s = "&nbsp;<select name=year style='font-size: 12px' "
    s += "onblur='document.all.tmpSelectYearLayer.style.display=\"none\"' "
    s += "onchange='document.all.tmpSelectYearLayer.style.display=\"none\";"
    s += "parent.meizzTheYear = this.value; parent.meizzSetDay(parent.meizzTheYear,parent.meizzTheMonth)'>\r\n";
    var selectInnerHTML = s;
    for (var i = n; i < n + 101; i++)
    {
        if (i == m) { selectInnerHTML += "<option value='" + i + "' selected>" + i + "年" + "</option>\r\n"; }
        else { selectInnerHTML += "<option value='" + i + "'>" + i + "年" + "</option>\r\n"; }
    }
    selectInnerHTML += "</select>";
    odatelayer.tmpSelectYearLayer.style.display="";
    odatelayer.tmpSelectYearLayer.innerHTML = selectInnerHTML;
    odatelayer.tmpSelectYear.focus();
}

function innitMonth(strMonth) //月份的下拉框
{
    if (strMonth.match(/\D/)!=null){alert("月份输入参数不是数字！");return;}
    var m = (strMonth) ? strMonth : new Date().getMonth() + 1;
    var s = "&nbsp;&nbsp;&nbsp;<select name=month style='font-size: 12px' "
    s += "onblur='document.all.tmpSelectMonthLayer.style.display=\"none\"' "
    s += "onchange='document.all.tmpSelectMonthLayer.style.display=\"none\";"
    s += "parent.meizzTheMonth = this.value; parent.meizzSetDay(parent.meizzTheYear,parent.meizzTheMonth)'>\r\n";
    var selectInnerHTML = s;
    for (var i = 1; i < 13; i++)
    {
        if (i == m) { selectInnerHTML += "<option value='"+i+"' selected>"+i+"月"+"</option>\r\n"; }
        else { selectInnerHTML += "<option value='"+i+"'>"+i+"月"+"</option>\r\n"; }
    }
    selectInnerHTML += "</select>";
    odatelayer.tmpSelectMonthLayer.style.display="";
    odatelayer.tmpSelectMonthLayer.innerHTML = selectInnerHTML;
    odatelayer.tmpSelectMonth.focus();
}